﻿using System;
using Assist;
using Autodesk.Revit.DB;

namespace YJKRevitAxisModule
{
	public class ViewHandle
	{
		public static bool SetViewPlan(Autodesk.Revit.DB.Document doc, Autodesk.Revit.DB.View activeView, ref string message)
		{
			if (activeView.GetType() == typeof(ViewPlan))
			{
				ViewPlan viewPlan = activeView as ViewPlan;
				if (viewPlan.SketchPlane == null)
				{
					Plane plane = RevitVersionFuncs.CreatePlanByOriginAndBasis(viewPlan.Origin, viewPlan.RightDirection, viewPlan.UpDirection);
					Transaction transaction = new Transaction(doc);
					transaction.Start("new sketchPlane");
					SketchPlane sketchPlane = RevitVersionFuncs.NewSketchPlane(doc, plane);
					activeView.SketchPlane = sketchPlane;
					transaction.Commit();
				}
				return true;
			}
			if (activeView.GetType() == typeof(ViewSection))
			{
				ViewSection viewSection = activeView as ViewSection;
				if (viewSection.SketchPlane == null)
				{
					Plane plane2 = RevitVersionFuncs.CreatePlanByOriginAndBasis(viewSection.Origin, viewSection.RightDirection, viewSection.UpDirection);
					Transaction transaction2 = new Transaction(doc);
					transaction2.Start("new sketchPlane");
					SketchPlane sketchPlane2 = RevitVersionFuncs.NewSketchPlane(doc, plane2);
					activeView.SketchPlane = sketchPlane2;
					transaction2.Commit();
				}
				return true;
			}
			message = "当前视图无法运行此命令";
			return false;
		}
	}
}
